//
//  LikeButton.m
//  Molian
//
//  Created by 胡津 on 15/4/13.
//  Copyright (c) 2015年 xiaocan. All rights reserved.
//

#import "LikeButton.h"

@implementation LikeButton
{
    UIView *cellview;
   
    
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        cellview = [[UIView alloc]init];
        cellview.clipsToBounds = NO;
        cellview.userInteractionEnabled = NO;
        cellview.layer.masksToBounds = YES;//开启圆角
        [cellview.layer setCornerRadius:frame.size.height/2];
        [self addSubview:cellview];
        
        
        self.icon = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width-20, (frame.size.height-12)/2, 12, 12)];
        _icon.image = [UIImage imageNamed:@"like_love"];
        [_icon setContentMode:UIViewContentModeScaleAspectFill];
        _icon.userInteractionEnabled = NO;
        [self addSubview:_icon];
        
        self.Title = [[UILabel alloc]init];
        self.Title.frame = CGRectMake(frame.size.width-125, 0, 100, frame.size.height);
        self.Title.textColor = [UIColor whiteColor];
        self.Title.textAlignment = NSTextAlignmentRight;
        self.Title.font = [UIFont fontWithName:FontName size:11];
//        self.Title.layer.cornerRadius = 7;
//        self.Title.layer.shadowColor = [UIColor grayColor].CGColor;
//        self.Title.layer.shadowOffset = CGSizeMake(1, 1);
//        self.Title.layer.shadowOpacity = 1;
//        self.Title.layer.shadowRadius = 5;
        self.Title.userInteractionEnabled = NO;
        [self addSubview:self.Title];

      
        
    }
    return self;
}

-(void)Like
{
    CABasicAnimation *animationZoomIn=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animationZoomIn.duration=0.25;
    animationZoomIn.autoreverses=YES;
    animationZoomIn.repeatCount = 0;
    animationZoomIn.toValue=[NSNumber numberWithFloat:1.56];
    animationZoomIn.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    [_icon.layer addAnimation:animationZoomIn forKey:nil];

    NSDictionary * dic = [[NSDictionary alloc]initWithObjectsAndKeys:self.Title.font,NSFontAttributeName,nil];
    CGSize size = [self.Title.text sizeWithAttributes:dic];
    cellview.frame=CGRectMake(self.frame.size.width - size.width-30 ,0, size.width + 30, self.frame.size.height);
    
}

-(void)Like:(BOOL)boll Alpha:(CGFloat)Alpha
{
    [self Like];
    if (boll == YES) {
        cellview.backgroundColor = APPCOLOR(Alpha);
    }else if (boll == NO){
        cellview.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:Alpha];
    }
}

-(void)layoutSubviews
{
    [super layoutSubviews];
//    NSDictionary * dic = [[NSDictionary alloc]initWithObjectsAndKeys:self.Title.font,NSFontAttributeName,nil];
//    CGSize size = [self.Title.text sizeWithAttributes:dic];
    cellview.frame=CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    self.Title.frame = CGRectMake(self.frame.size.width-125, 0, 100, self.frame.size.height);
    if (self.isRead) {
        _icon.frame = CGRectMake(self.frame.size.width-21, (self.frame.size.height-7)/2, 13, 7);
    }else{
         _icon.frame = CGRectMake(self.frame.size.width-20, (self.frame.size.height-12)/2, 12, 12);
    }
   

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
